﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace PIM_ATE.rflight
{
    public partial class FrmDeviceDebugComRF : Form
    {
        ClsRfPimCmdCom m_rfCom;
        public FrmDeviceDebugComRF()
        {
            InitializeComponent();
        }

        private void FrmDeviceDebugComRF_Load(object sender, EventArgs e)
        {
            m_rfCom = new ClsRfPimCmdCom();
            cb_com.Items.AddRange(SerialPort.GetPortNames());
            cb_com.SelectedIndex = 0;

            cb_cmd.Items.Add("0.getIDN");
            cb_cmd.Items.Add("1.Reset");
            cb_cmd.Items.Add("2.getBandSize");
            cb_cmd.Items.Add("3.setFreqBand");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string line = "\r\n";
            switch (cb_cmd.SelectedIndex)
            {
                case 0:
                    txt_Mes.AppendText(m_rfCom.getIDN() + line);
                    break;
                case 1:
                    txt_Mes.AppendText(m_rfCom.Reset() == true ? "True" : "False" + line);
                    break;
                case 2:
                    txt_Mes.AppendText(m_rfCom.getBandSize() + line);
                    break;
                case 3:
                    m_rfCom.setFreqBand();
                    txt_Mes.AppendText(m_rfCom.getFreqBand() + line);
                    break;

            }
        }

        private void btn_Connect_Click(object sender, EventArgs e)
        {
            m_rfCom.Connect(cb_com.Text);
        }

        private void btn_Close_Click(object sender, EventArgs e)
        {
            m_rfCom.Close();
        }

        private void FrmDeviceDebugComRF_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_rfCom.Close();
        }
    }
}
